package org.wisdom.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 工具类
 *
 * @author 张智研
 * @date 2022/05/27 15:30
 **/
public class WisdomUtil {
    /** 匹配{xxx}类型变量 */
    public static final String EXP1 = "\\{(.*?)}";
    /** 匹配${xxx}类型变量 */
    public static final String EXP2 = "\\$\\{(.*?)}";

    private WisdomUtil() {}

    /**
     * 正则表达式获取字符串中变量
     *
     * @author 张智研
     * @date 2022/05/27 15:33
     * @param value
     *            字符串
     * @param exp
     *            正则表达式
     * @return java.lang.String[]
     */
    public static String[] getParams(String value, String exp) {
        Pattern pattern = Pattern.compile(exp);
        Matcher matcher = pattern.matcher(value);
        List<String> matches = new ArrayList<>();
        while (matcher.find()) {
            String group = matcher.group();
            matches.add(group);
        }
        return matches.toArray(new String[0]);
    }

}
